package com.hdjk.view.callback;

import com.hdjk.view.entity.BuyFeeAndChargeEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONObject;

import java.math.BigDecimal;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class GetBuyFeeAndChargeCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg = super.parseNetworkResponse(response, i);
        JSONObject object = (JSONObject) msg.getData();
        if (object!=null) {
            BuyFeeAndChargeEntity entity = new BuyFeeAndChargeEntity();
            if (!object.isNull("discountRate")) {
                double l = object.getDouble("discountRate") * 100;
                BigDecimal b = new BigDecimal(l);
                entity.setDiscountRate(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("discountSalesCharge")) {
                double l = object.getDouble("discountSalesCharge");
                BigDecimal b = new BigDecimal(l);
                entity.setDiscountSalesCharge(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("fixedSalseCharge")) {
                entity.setFixedSalseCharge(object.getString("fixedSalseCharge"));
            }
            if (!object.isNull("salesCharges")) {
                double l = object.getDouble("salesCharges");
                BigDecimal b = new BigDecimal(l);
                entity.setSalesCharges(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("salesChargesRate")) {
                double l = object.getDouble("salesChargesRate");
                BigDecimal b = new BigDecimal(l);
                entity.setSalesChargesRate(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            msg.setData(entity);
        }
        return msg;
    }
}
